package com.test.jbpm.dao.impl;


import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.stereotype.Repository;

import com.test.jbpm.dao.DeptDao;
import com.test.jbpm.domain.Dept;


@Repository
public class DeptDaoImpl extends BaseDao implements DeptDao {

	@SuppressWarnings("unchecked")
	public List<Dept> findDeptList() {
		return getHibernateTemplate().find("from Dept d order by d.id");
	}
	public Dept findFirstLevelOfTree(){
		return (Dept) getHibernateTemplate().execute(new HibernateCallback(){
			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {
				// TODO Auto-generated method stub
				return session.createQuery("from Dept d where pid is null").uniqueResult();
			}		
		});
	}
}
